package ucd.csi.comp30220.fall2011.oteop.flight;

import ucd.csi.comp30220.fall2011.oteop.flight.impl.RemoteFlightClient;

public final class FlightFinder {
    
    static { new FlightFinder(); }
    public FlightFinder() { }
    
    /**
     * Tries to find the flight running somewhere else on the network. 
     * 
     * @param flightNumber 
     *              Number of the flight to fond. "BA123", for instance.
     *              
     * @return the Flight if it can be found, <code>null</code> otherwise
     */
    public static Flight find(String flightNumber) {
        return find(flightNumber, 10*1000);
    }

    /**
     * Tries to find the flight running somewhere else on the network. 
     * 
     * @param flightNumber 
     *              Number of the flight to fond. "BA123", for instance.
     * @param timeout 
     *              how long (ms) to wait for the flight to be found
     *              
     * @return the Flight if it can be found, <code>null</code> otherwise
     */
    public static Flight find(String flightNumber, long timeout) {
        try {
            return new RemoteFlightClient(flightNumber, timeout);
        } catch (Exception e) { 
            return null;
        }
    }

}
